package leetcode.editor.week.week309;

import leetcode.editor.week.week306.Solution6150;

// 6169. 最长优雅子数组
// https://leetcode.cn/contest/weekly-contest-309/problems/longest-nice-subarray/
class Solution6169 {
    public int longestNiceSubarray(int[] nums) {
        int l = 0, r = 0, res = 0;
        while (r < nums.length) {
            for (int i = l; i < r; i++) {
                int m = nums[r];
                int n = nums[i];
                while (n != 0) {
                    int t = (n % 2) & (m % 2);
                    if (t != 0) {
                        l = i + 1;
                        break;
                    }
                    m >>= 1;
                    n >>= 1;
                }
            }

            res = Math.max(res, r - l + 1);

            r++;
        }
        return res;
    }
}